<!DOCTYPE html>
<html lang="en" class="x-admin-sm" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>作品管理页面</title>
    <header th:replace="header::html"></header>
    <link th:href="@{/xadmin/lib/layui/css/layui.css}" rel="stylesheet" type="text/css"/>
    <script th:src="@{/xadmin/lib/layui/layui.js}" type="text/javascript"></script>
</head>

<body>

    <div class="layui-fluid">
        <div class="layui-row  layui-col-space15">
            <div class="layui-col-md12">
                <div class="layui-card">
                    <div class="layui-card-body ">
                        <form class="layui-form  layui-col-space5">
                            <div class="layui-inline layui-show-xs-block">
                                <input type="text" name="workName" id="workName" placeholder="作品标题或内容关键字" autocomplete="off"
                                       class="layui-input">
                            </div>
                            <div class="layui-inline">
                                <div class="layui-input-inline">
                                    <input type="text" class="layui-input" id="startDate" placeholder="请选择开始日期"
                                           name="startDate">
                                </div>
                            </div>
                            <div class="layui-inline">
                                <div class="layui-input-inline">
                                    <input type="text" class="layui-input" id="endDate" placeholder="请选择结束日期" name="endDate">
                                </div>
                            </div>
                            <div class="layui-inline">
                                <div class="layui-input-inline">
                                    <select name="verifyStatus" id="verifyStatus" class="layui-select">
                                        <option value="" selected="selected">--审核状态--</option>
                                        <option value="待审核">待审核</option>
                                        <option value="已审核">已审核</option>
                                        <option value="未过审">未过审</option>
                                    </select>
                                </div>
                            </div>
                            <div class="layui-inline layui-show-xs-block">
                                <button class="layui-btn" lay-submit="" lay-filter="search"><i
                                        class="layui-icon">&#xe615;</i></button>
                            </div>
                        </form>
                    </div>
                    <div class="layui-card-body ">
                        <table class="layui-hide" id="workTable" lay-filter="workTable" ></table>
                    </div>
                    <script type="text/html" id="barDemo">
                        <a class="layui-btn layui-btn-xs layui-btn-normal" lay-event="details">详情</a>
                        <a class="layui-btn layui-btn-xs layui-btn-normal" lay-event="download">下载</a>
                        {{#  if(d.wstatus ==='待审核'){ }}
                        <a class="layui-btn layui-btn-xs" lay-event="review-yes" >通过</a>
                        <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="review-no">不通过</a>
                        {{#  } else if(d.wstatus==='未过审'){ }}
                        <a class="layui-btn layui-btn-xs" lay-event="delete" >删除</a>
                        {{#  } }}
                    </script>
                </div>
            </div>
        </div>
    </div>
</body>
<script>

	layui.use('laydate', function () {
		var laydate = layui.laydate;
		//选中后的回调
		laydate.render({
			elem: '#startDate'
			, done: function (value, date) {
				// layer.alert('你选择的日期是：' + value + '<br>获得的对象是' + JSON.stringify(date));
			}
		});

		laydate.render({
			elem: '#endDate'
			, done: function (value, date) {
				// layer.alert('你选择的日期是：' + value + '<br>获得的对象是' + JSON.stringify(date));
			}
		});
	});


	layui.use(['table','form','layer'], function () {
		var table = layui.table,
            layer=layui.layer,
			form = layui.form;
		layer.msg('点击表格显示不全内容，可以查看具体内容详情',{icon:6});
		table.render({
			elem: '#workTable'
			, url: '/api-back/verifyWork/workDeploy' //数据接口
			, page: true //开启分页
			, cellMinWidth: 80 //全局定义常规单元格的最小宽度
			, limits:[10,20]
			, limit:10
			, response: {
				dataName: 'datas' //规定数据列表的字段名称，默认：data
			}
			, cols: [
				[
					{type:'numbers' ,align:'center'}
					,{field:'wid', align:'center',width: '1%',title: '作品表id',style:'display:none;'}
					,{field:'fname', align:'center',width: '1%',title: '文件名',style:'display:none;'}
					,{field:'wuseraccount', align:'center',width: '1%',title: '用户id',style:'display:none;'}
					,{field:'wtitle', align:'center',width: '14%',title: '作品标题',event:'coltitle'}
					,{field:'wcontent', title: '作品描述',width: '23%',align:'center',event:'colcontent'}
					,{field:'wmoney',align:'center',width: '6%',title: '价格'}
					,{field:'wstarttime', align:'center',width: '8%', title: '发布时间'}
					,{field:'uname', align:'center',width: '15%', title: '服务商',event:'colname',templet:function (msg) {
                        return msg.uname+"(ID:"+msg.wuseraccount+")"
					}}
					,{field:'wstatus', align:'center', title: '状态',width: '6%'}
					,{ fixed: 'right', title: '操作',  align: 'left',width: 260, toolbar: '#barDemo'}
				]
			],
			done: function () {
				//checkPermission();
			}

		});
		$('table.layui-table thead tr th:eq(1)').addClass('layui-hide');//隐藏的曝光表id表头
		$('table.layui-table thead tr th:eq(2)').addClass('layui-hide');//隐藏的曝光表id表头
		$('table.layui-table thead tr th:eq(3)').addClass('layui-hide');//隐藏的曝光表id表头

		//监听行工具事件
		table.on('tool(workTable)', function(obj) { //注：tool 是工具条事件名，test 是 table 原始容器的属性 lay-filter="对应的值"
			var data = obj.data ,//获得当前行数据
				layEvent = obj.event, //获得 lay-event 对应的值
                wid=data.wid,
			    fname=data.fname,
                coltitle=data.wtitle,
                colcontent=data.wcontent,
                colname=data.uname,
			    wuseraccount=data.wuseraccount;
			if(layEvent === 'delete') {
				layer.confirm('确定要删除该条记录吗？删除后不可恢复',function (index) {
					$.ajax({
						type:"post",
						url:'/api-back/verifyWork/work-delete',
						data:{"wid":wid},
						success:function (msg) {
							if (msg === "success") {
								layer.msg("删除成功",{icon:1});
								$(".layui-laypage-btn")[0].click();
							} else {
								layer.msg("删除失败，请重试",{icon:2})
							}
						},
						error:function (msg) {
							layer.open({
								type:2,
								content: "/404.html",
								area:['1000px','600px'],
								title:'权限不允许进行访问'
							})
						}
					})
				})
			}
			else if(layEvent === 'review-yes'){
				layer.confirm('确定通过审核吗？',function (index) {
					$.ajax({
						url:'/api-back/verifyWork/work-yes',
                        type:"post",
						data:{"wid":wid},
						success:function (msg) {
							if (msg === "success") {
								layer.msg("审核成功，作品发布",{icon:1});
								$(".layui-laypage-btn")[0].click();
							} else {
								layer.msg("审核操作失败，请重试",{icon:2})
							}
						},
						error:function (msg) {
							layer.open({
								type:2,
								content: "/404.html",
								area:['1000px','600px'],
								title:'权限不允许进行访问'
							})
						}
					})
				})
			}
			else if (layEvent === 'review-no') {
				layer.confirm('审核不通过吗？作品会被同时删除，记录暂存',function (index) {
					$.ajax({
						url:'/api-back/verifyWork/work-no',
                        type:"post",
						data:{"wid":wid,"fname":fname,"wuseraccount":wuseraccount},
						success:function (msg) {
							if (msg === "success") {
								layer.msg("审核不通过，作品删除，记录暂存",{icon:1});
								$(".layui-laypage-btn")[0].click();
							} else {
								layer.msg("审核操作失败，请重试",{icon:2})
							}
						},
						error:function (msg) {
							layer.open({
								type:2,
								content: "/404.html",
								area:['1000px','600px'],
								title:'权限不允许进行访问'
							})
						}
					})
				})
			}
			else if (layEvent === 'download') {
                    window.location.href='/api-back/verifyWork/work-download?fname='+fname+'&wuseraccount='+wuseraccount;
			}
			else if (layEvent === 'details') {
                $.ajax({
	                url:'/api-back/verifyWork/work-details',
                    type:"post",
                    data:{"wid":wid},
                    success:function (msg) {
	                    layer.open({
		                    type: 1 //Page层类型
		                    ,area: ['600px', '450px']
		                    ,title: '查看作品详情'
		                    ,shade: 0.3 //遮罩透明度
		                    ,anim: 1 //0-6的动画形式，-1不开启
		                    ,content:
                                '<div style="padding:50px;font-size: 15px"><div><p>服务商：'+msg.uname+'&nbsp;(ID:'+msg.wuseraccount+')</p></div><br><div><p>作品标题：'+msg.wtitle+'</p></div><br><div><p>作品描述：'+msg.wcontent+'</p></div><br><div><p>作品名称：'+msg.fname+'</p></div><br><div><p>作品类型：'+msg.type+'</p></div><br><div><p>作品价格：'+msg.wmoney+'(CNY)</p></div><br><div><p>发布时间：'+msg.wstarttime+'</p></div></div>'
	                    });
                    },
                    error:function (msg) {
	                    layer.open({
		                    type:2,
		                    content: "/404.html",
		                    area:['1000px','600px'],
		                    title:'权限不允许进行访问'
	                    })
	                }
                })
			} else if (layEvent === 'coltitle') {
				layer.alert(coltitle)
			} else if (layEvent === 'colcontent') {
				layer.alert(colcontent)
			} else if (layEvent === 'colname') {
				layer.alert(colname+"(ID:"+wuseraccount+")")
			}
		});

		//搜索
		form.on('submit(search)', function (data) {
			var field = data.field;
			if (dateCompare(field.startDate, field.endDate)) {
				table.render({
					elem: '#workTable'
					, url: '/api-back/verifyWork/workDeploy' //数据接口
					, page: true //开启分页
					, limits:[10,20]
					, limit:10
					, where: {
						"workName": field.workName,
						"starttime": field.startDate,
						"endtime": field.endDate,
						"verifyStatus":field.verifyStatus
					}
					, response: {
						dataName: 'datas' //规定数据列表的字段名称，默认：data
					}
					, cols: [
						[
							{type:'numbers' ,align:'center'}
							,{field:'wid', align:'center',width: '1%',title: '作品表id',style:'display:none;'}
							,{field:'fname', align:'center',width: '1%',title: '文件名',style:'display:none;'}
							,{field:'wuseraccount', align:'center',width: '1%',title: '用户id',style:'display:none;'}
							,{field:'wtitle', align:'center',width: '14%',title: '作品标题',event:'coltitle'}
							,{field:'wcontent', title: '作品描述',width: '23%',align:'center',event:'colcontent'}
							,{field:'wmoney',align:'center',width: '6%',title: '价格'}
							,{field:'wstarttime', align:'center',width: '8%', title: '发布时间'}
							,{field:'uname', align:'center',width: '15%',event:'colname', title: '服务商',templet:function (msg) {
								return msg.uname+"(ID:"+msg.wuseraccount+")"
							}}
							,{field:'wstatus', align:'center', title: '状态',width: '6%'}
							,{ fixed: 'right', title: '操作',  align: 'left',width: 260, toolbar: '#barDemo'}
						]
					]
				});
				$('table.layui-table thead tr th:eq(1)').addClass('layui-hide');//隐藏的曝光表id表头
				$('table.layui-table thead tr th:eq(2)').addClass('layui-hide');//隐藏的曝光表id表头
				$('table.layui-table thead tr th:eq(3)').addClass('layui-hide');//隐藏的曝光表id表头

			} else {
				layer.msg("您的日期不正确，请重新输入！",{icon:2});
			}
			return false;
		});
		//checkPermission();
	});

	function dateCompare(startDate, endDate) {
		var oDate1 = new Date(startDate);
		var oDate2 = new Date(endDate);
		if (oDate1 > oDate2) {
			return false;
		} else {
			return true;
		}
	}


</script>
</html>